<?php

namespace app\api\services;

use GuzzleHttp\Client;
use think\Db;
use think\exception\HttpException;
use think\Log;


class ProxyIP2
{
    private static $proxy_url = [
        [
            'url' => 'http://14784202728.v4.dailiyun.com/query.txt?key=NP1DA27C0E&word=&count=1&rand=false&ltime=240&norepeat=true&detail=false',
            'username' => '14784202728',
            'password' => '123321',
        ],
        [
            'url' => 'http://shiwei040302.v4.dailiyun.com/query.txt?key=NPE97559C4&word=&count=1&rand=false&ltime=240&norepeat=true&detail=false',
            'username' => 'shiwei040302',
            'password' => '123456',
        ],
        [
            'url' => 'http://shiwei0403.v4.dailiyun.com/query.txt?key=NP0CFBD419&word=&count=1&rand=false&ltime=240&norepeat=true&detail=false',
            'username' => 'shiwei0403',
            'password' => '123321',
        ],
    ];

    private static $XiaoXiongProxyUrl = 'http://find.xiaoxiongcloud.com/find_http?key=e65cc00a9eb53d25&count=1&type=json&only=1&pw=no';
    private static $ZhiMaProxyUrl = [
        'url'=>'http://http.tiqu.letecs.com/getip3?num=1&type=2&pro=0&city=0&yys=0&port=1&pack=162359&ts=0&ys=0&cs=1&lb=1&sb=0&pb=4&mr=2&regions=130000,140000,210000,220000,320000,330000,340000,350000,360000,370000,410000,420000,430000,440000,460000,500000,510000,520000,610000&gm=4&username=chukou01&spec=1',
        'username'=>'18538188035',
        'password'=>'123321'
    ];

    private static $ShanDongZhiMaProxyUrl = [
        'url'=>'http://http.tiqu.letecs.com/getip3?num=1&type=1&pro=0&city=0&yys=0&port=1&pack=162359&ts=0&ys=0&cs=0&lb=1&sb=0&pb=4&mr=1&regions=370000&gm=4&username=chukou01&spec=1',
        'username'=>'18538188035',
        'password'=>'123321'
    ];

    private static $ZDaYeProxyUrl = [
        'url'=>'http://www.zdopen.com/ShortProxy/GetIP/?api=202111081635572419&akey=68a681d0bd26e5eb&timespan=4&type=3',
        'username'=>'202111081635572419',
        'password'=>'53707405'
    ];
    private static $TianQiProxyUrl = [
        'url'=>'http://api.tianqiip.com/getip?secret=5mrmz3kk&type=json&num=1&port=1',
        'username'=>'h6pkgr',
        'password'=>'qewrn8xz'
    ];

    private static $getLocationUrl ='http://opendata.baidu.com/api.php?co=&resource_id=6006&oe=utf8&query=';

    private static $ShenLongProxyUrl = [
        'url'=>'http://api.shenlongip.com/ip?key=z56g96mh&pattern=json&count=1&need=1010&protocol=1',
        'username'=>'05yo9w',
        'password'=>'6hm0u4q5'
    ];


    /**
     * 获取代理IP
     * @param array $param
     * @return array|null
     * @throws \GuzzleHttp\Exception\GuzzleException
     * type=reap 使用代理云 shiwei0403 这个账号
     * type=dsp 优先使用芝麻代理的18538188035，其次使用小熊代理
     * type=create 优先使用小熊代理，其次使用芝麻
     * type=job  代理云14784202728和shiwei040302  保持1:1的比例分配
     */
    public function getTask($param=[])
    {
        $timeout = [
            'http'=>[
                'timeout'=>5
            ]
        ];
        $ctx = stream_context_create($timeout);
        try{
            $redis = new \Redis();
            $redis->connect('127.0.0.1', 6379);
            $redis->select(2);
            if($param['type'] == 'reap'){
                if(isset($param['from']) && in_array($param['from'],['zhima','xiaoxiong'])){
                    if($param['from'] == 'zhima'){
                        //10秒钟不能超过50次-------redis--队列
                        $zhima_len = $redis->llen('zhima_timestamp');
                        if($zhima_len >= 0 && $zhima_len < 50){
                            $redis->rpush('zhima_timestamp',time());
                        }elseif($zhima_len >= 50){
                            $key_49 = $redis->lindex('zhima_timestamp',$zhima_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('zhima_timestamp',time());
                        }

                        $res = file_get_contents(self::$ZhiMaProxyUrl['url'],0,$ctx);

                        $this->mysql_insert($res,'zhima',self::$ZhiMaProxyUrl['username']);
                        if($res){
                            $arr = json_decode($res,true);

                            if(isset($arr['success'])){
                                if(isset($arr['data']) && !empty($arr['data'])){
                                    $proxy['ip'] = $arr['data'][0]['ip'];
                                    $proxy['originIp'] = $arr['data'][0]['outip'];
                                    $proxy['port'] = $arr['data'][0]['port'];
                                    $proxy['User'] = self::$ZhiMaProxyUrl['username'];
                                    $proxy['Password'] = self::$ZhiMaProxyUrl['password'];
                                    $proxy['from'] = 'zhima';

                                    $realIp = $proxy['originIp'];
                                    //获取 IP 所属地区
                                    $location = self::getIpLocation($realIp);
                                    if(!$location){
                                        $location_address[0] = '未知';
                                    }
                                    $location_address = explode(' ',$location);
                                    $response_arr = [
                                        'IP'=>$proxy['ip'],
                                        'RealIP'=>$realIp,
                                        'Port'=>intval($proxy['port']),
                                        'Address'=>'',
                                        'User'=>$proxy['User'],
                                        'Password'=>$proxy['Password'],
                                        'Location'=>$location_address[0],
                                        'Isp'=>$location_address[1] ?? '未知',
                                        'From'=>$proxy['from'],
                                    ];
                                    return $response_arr;
                                }else{
                                    return null;
                                }
                            }else{
                                return null;
                            }
                        }
                    }elseif ($param['from'] == 'xiaoxiong'){
                        //10秒钟不能超过50次-------redis--队列
                        $xiaoxiong_len = $redis->llen('xiaoxiong_timestamp');
                        if($xiaoxiong_len >= 0 && $xiaoxiong_len < 50){
                            $redis->rpush('xiaoxiong_timestamp',time());
                        }elseif($xiaoxiong_len >= 50){
                            $key_49 = $redis->lindex('xiaoxiong_timestamp',$xiaoxiong_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('xiaoxiong_timestamp',time());
                        }
//                        dump(25);die;
                        $res = file_get_contents(self::$XiaoXiongProxyUrl,0,$ctx);
                        $this->mysql_insert($res,'xiaoxiong','');
                        if($res){
                            $arr = json_decode($res,true);
                            if($arr['status'] == 0){
                                if(isset($arr['list']) && !empty($arr['list'])){
                                    $proxy['ip'] = $arr['list'][0]['sever'];
                                    $proxy['originIp'] = $arr['list'][0]['ip'];
                                    $proxy['port'] = $arr['list'][0]['port'];
                                    $proxy['User'] = '';
                                    $proxy['Password'] = '';
                                    $proxy['from'] = 'xiaoxiong';

                                    $realIp = $proxy['originIp'];
                                    //获取 IP 所属地区
                                    $location = self::getIpLocation($realIp);
                                    if(!$location){
                                        $location_address[0] = '未知';
                                    }
                                    $location_address = explode(' ',$location);
                                    $response_arr = [
                                        'IP'=>$proxy['ip'],
                                        'RealIP'=>$realIp,
                                        'Port'=>intval($proxy['port']),
                                        'Address'=>'',
                                        'User'=>$proxy['User'],
                                        'Password'=>$proxy['Password'],
                                        'Location'=>$location_address[0],
                                        'Isp'=>$location_address[1] ?? '未知',
                                        'From'=>$proxy['from'],
                                    ];
                                    return $response_arr;
                                }else{
                                    return null;
                                }
                            }else{
                                return null;
                            }
                        }
                    }
                }
                //10秒钟不能超过200次，五分钟不能超过500
                $dailiun_3_len = $redis->llen('dailiun_3_timestamp');
                if($dailiun_3_len >= 0 && $dailiun_3_len < 50){
                    $redis->rpush('dailiun_3_timestamp',time());
                }elseif($dailiun_3_len >= 50){
                    $key_49 = $redis->lindex('dailiun_3_timestamp',$dailiun_3_len-49);
                    if(time() - $key_49 <= 10){
                        return false;
                    }
                    $redis->rpush('dailiun_3_timestamp',time());
                }

                $proxy_url_1 = static::$proxy_url;
                $res = file_get_contents($proxy_url_1[2]['url'],0,$ctx);
                $this->mysql_insert($res,'dailiyun',$proxy_url_1[2]['username']);
                $arr = explode(':',$res);
                if(count($arr) == 2){
                    $proxy=[
                        'ip'=>$arr[0],
                        'port' => $arr[1],
                        'User' => $proxy_url_1[2]['username'],
                        'Password' => $proxy_url_1[2]['password'],
                        'from' => 'dailiyun'
                    ];
                    $realIp = $proxy['ip'];
                    //获取 IP 所属地区
                    $location = self::getIpLocation($realIp);
                    if(!$location){
                        $location_address[0] = '未知';
                    }
                    $location_address = explode(' ',$location);
                    $response_arr = [
                        'IP'=>$proxy['ip'],
                        'RealIP'=>$realIp,
                        'Port'=>intval($proxy['port']),
                        'Address'=>'',
                        'User'=>$proxy['User'],
                        'Password'=>$proxy['Password'],
                        'Location'=>$location_address[0],
                        'Isp'=>$location_address[1] ?? '未知',
                        'From'=>$proxy['from'],
                    ];
                    return $response_arr;
                }

                //如果走代理云获取不到，再走芝麻获取一次--2021-10-22
                //10秒钟不能超过50次-------redis--队列
                $zhima_len = $redis->llen('zhima_timestamp');
                if($zhima_len >= 0 && $zhima_len < 50){
                    $redis->rpush('zhima_timestamp',time());
                }elseif($zhima_len >= 50){
                    $key_49 = $redis->lindex('zhima_timestamp',$zhima_len-49);
                    if(time() - $key_49 <= 10){
                        return false;
                    }
                    $redis->rpush('zhima_timestamp',time());
                }

                $res = file_get_contents(self::$ZhiMaProxyUrl['url'],0,$ctx);

                $this->mysql_insert($res,'zhima',self::$ZhiMaProxyUrl['username']);
                if($res){
                    $arr = json_decode($res,true);

                    if(isset($arr['success'])){
                        if(isset($arr['data']) && !empty($arr['data'])){
                            $proxy['ip'] = $arr['data'][0]['ip'];
                            $proxy['originIp'] = $arr['data'][0]['outip'];
                            $proxy['port'] = $arr['data'][0]['port'];
                            $proxy['User'] = self::$ZhiMaProxyUrl['username'];
                            $proxy['Password'] = self::$ZhiMaProxyUrl['password'];
                            $proxy['from'] = 'zhima';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }else{
                            return null;
                        }
                    }else{
                        return null;
                    }
                }
            }elseif ($param['type'] == 'create'){
                //10秒钟不能超过50次-------redis--队列
                $xiaoxiong_len = $redis->llen('xiaoxiong_timestamp');
                if($xiaoxiong_len >= 0 && $xiaoxiong_len < 50){
                    $redis->rpush('xiaoxiong_timestamp',time());
                }elseif($xiaoxiong_len >= 50){
                    $key_49 = $redis->lindex('xiaoxiong_timestamp',$xiaoxiong_len-49);
                    if(time() - $key_49 <= 10){
                        return false;
                    }
                    $redis->rpush('xiaoxiong_timestamp',time());
                }

                $res = file_get_contents(self::$XiaoXiongProxyUrl,0,$ctx);
                $this->mysql_insert($res,'xiaoxiong','');
                if($res){
                    $arr = json_decode($res,true);
                    if($arr['status'] == 0){
                        if(isset($arr['list']) && !empty($arr['list'])){
                            $proxy['ip'] = $arr['list'][0]['sever'];
                            $proxy['originIp'] = $arr['list'][0]['ip'];
                            $proxy['port'] = $arr['list'][0]['port'];
                            $proxy['User'] = '';
                            $proxy['Password'] = '';
                            $proxy['from'] = 'xiaoxiong';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }
                    }
                }

                //10秒钟不能超过50次-------redis--队列
                $zhima_len = $redis->llen('zhima_timestamp');
                if($zhima_len >= 0 && $zhima_len < 50){
                    $redis->rpush('zhima_timestamp',time());
                }elseif($zhima_len >= 50){
                    $key_49 = $redis->lindex('zhima_timestamp',$zhima_len-49);
                    if(time() - $key_49 <= 10){
                        return false;
                    }
                    $redis->rpush('zhima_timestamp',time());
                }

                $res = file_get_contents(self::$ZhiMaProxyUrl['url'],0,$ctx);
                $this->mysql_insert($res,'zhima',self::$ZhiMaProxyUrl['username']);
                if($res){
                    $arr = json_decode($res,true);
                    if(isset($arr['success'])){
                        if(isset($arr['data']) && !empty($arr['data'])){
                            $proxy['ip'] = $arr['data'][0]['ip'];
                            $proxy['originIp'] = $arr['data'][0]['outip'];
                            $proxy['port'] = $arr['data'][0]['port'];
                            $proxy['User'] = self::$ZhiMaProxyUrl['username'];
                            $proxy['Password'] = self::$ZhiMaProxyUrl['password'];
                            $proxy['from'] = 'zhima';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }
                    }
                }
            }elseif ($param['type'] == 'dsp'){  //优先使用芝麻代理的18538188035，其次使用小熊代理
                //10秒钟不能超过50次-------redis--队列
                $zhima_len = $redis->llen('zhima_timestamp');
                if($zhima_len >= 0 && $zhima_len < 50){
                    $redis->rpush('zhima_timestamp',time());
                }elseif($zhima_len >= 50){
                    $key_49 = $redis->lindex('zhima_timestamp',$zhima_len-49);
                    if(time() - $key_49 <= 10){
                        return false;
                    }
                    $redis->rpush('zhima_timestamp',time());
                }
                $res = file_get_contents(self::$ZhiMaProxyUrl['url'],0,$ctx);
                $this->mysql_insert($res,'zhima',self::$ZhiMaProxyUrl['username']);
                if($res){
                    $arr = json_decode($res,true);
                    if(isset($arr['success'])){
                        if(isset($arr['data']) && !empty($arr['data'])){
                            $proxy['ip'] = $arr['data'][0]['ip'];
                            $proxy['originIp'] = $arr['data'][0]['outip'];
                            $proxy['port'] = $arr['data'][0]['port'];
                            $proxy['User'] = self::$ZhiMaProxyUrl['username'];
                            $proxy['Password'] = self::$ZhiMaProxyUrl['password'];
                            $proxy['from'] = 'zhima';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }
                    }
                }

                //10秒钟不能超过50次-------redis--队列
                $xiaoxiong_len = $redis->llen('xiaoxiong_timestamp');
                if($xiaoxiong_len >= 0 && $xiaoxiong_len < 50){
                    $redis->rpush('xiaoxiong_timestamp',time());
                }elseif($xiaoxiong_len >= 50){
                    $key_49 = $redis->lindex('xiaoxiong_timestamp',$xiaoxiong_len-49);
                    if(time() - $key_49 <= 10){
                        return false;
                    }
                    $redis->rpush('xiaoxiong_timestamp',time());
                }
                $res = file_get_contents(self::$XiaoXiongProxyUrl,0,$ctx);
                $this->mysql_insert($res,'xiaoxiong','');
                if($res){
                    $arr = json_decode($res,true);
                    if($arr['status'] == 0){
                        if(isset($arr['list']) && !empty($arr['list'])){
                            $proxy['ip'] = $arr['list'][0]['sever'];
                            $proxy['originIp'] = $arr['list'][0]['ip'];
                            $proxy['port'] = $arr['list'][0]['port'];
                            $proxy['User'] = '';
                            $proxy['Password'] = '';
                            $proxy['from'] = 'xiaoxiong';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }
                    }
                }

            }elseif ($param['type'] == 'job'){
                if(isset($param['from']) && !empty($param['from'])){
                    if($param['from'] == 'dailiyun'){
                        $round_1 = rand(0,100);
                        if($round_1 <= 50){
                            //10秒钟不能超过200次，五分钟不能超过700-------redis--队列
                            $dailiun_1_len = $redis->lLen('dailiun_1_timestamp');
                            if($dailiun_1_len >= 0 && $dailiun_1_len < 50){
                                $redis->rpush('dailiun_1_timestamp',time());
                            }elseif($dailiun_1_len >= 50){
                                $key_49 = $redis->lindex('dailiun_1_timestamp',$dailiun_1_len-49);
                                if(time() - $key_49 <= 10){
                                    return false;
                                }
                                $redis->rpush('dailiun_1_timestamp',time());
                            }

                            //暂时停掉代理云 1

                        }else{

                            //10秒钟不能超过200次，五分钟不能超过650
                            //暂时停掉
                            return false;
                            /*$dailiun_2_len = $redis->llen('dailiun_2_timestamp');
                            if($dailiun_2_len >= 0 && $dailiun_2_len < 50){
                                $redis->rpush('dailiun_2_timestamp',time());
                            }elseif($dailiun_2_len >= 50){
                                $key_49 = $redis->lindex('dailiun_2_timestamp',$dailiun_2_len-49);
                                if(time() - $key_49 <= 10){
                                    return false;
                                }
                                $redis->rpush('dailiun_2_timestamp',time());
                            }

                            $proxy_url_1 = static::$proxy_url;
                            $res = file_get_contents($proxy_url_1[1]['url'],0,$ctx);
                            $this->mysql_insert($res,'dailiyun',$proxy_url_1[1]['username']);
                            $arr = explode(':',$res);
                            if(count($arr) == 2){
                                $proxy=[
                                    'ip'=>$arr[0],
                                    'port' => $arr[1],
                                    'User' => $proxy_url_1[1]['username'],
                                    'Password' => $proxy_url_1[1]['password'],
                                    'from' => 'dailiyun'
                                ];
                                $realIp = $proxy['ip'];
                                //获取 IP 所属地区
                                $location = self::getIpLocation($realIp);
                                if(!$location){
                                    $location_address[0] = '未知';
                                }
                                $location_address = explode(' ',$location);
                                $response_arr = [
                                    'IP'=>$proxy['ip'],
                                    'RealIP'=>$realIp,
                                    'Port'=>intval($proxy['port']),
                                    'Address'=>'',
                                    'User'=>$proxy['User'],
                                    'Password'=>$proxy['Password'],
                                    'Location'=>$location_address[0],
                                    'Isp'=>$location_address[1] ?? '未知',
                                    'From'=>$proxy['from'],
                                ];
                                return $response_arr;
                            }*/
                        }
                    }elseif ($param['from'] == 'zhima'){
                        //10秒钟不能超过50次-------redis--队列
                        $zhima_len = $redis->llen('zhima_timestamp');
                        if($zhima_len >= 0 && $zhima_len < 50){
                            $redis->rpush('zhima_timestamp',time());
                        }elseif($zhima_len >= 50){
                            $key_49 = $redis->lindex('zhima_timestamp',$zhima_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('zhima_timestamp',time());
                        }
                        $res = file_get_contents(self::$ZhiMaProxyUrl['url'],0,$ctx);
                        $this->mysql_insert($res,'zhima',self::$ZhiMaProxyUrl['username']);
                        if($res){
                            $arr = json_decode($res,true);
                            if(isset($arr['success'])){
                                if(isset($arr['data']) && !empty($arr['data'])){
                                    $proxy['ip'] = $arr['data'][0]['ip'];
                                    $proxy['originIp'] = $arr['data'][0]['outip'];
                                    $proxy['port'] = $arr['data'][0]['port'];
                                    $proxy['User'] = self::$ZhiMaProxyUrl['username'];
                                    $proxy['Password'] = self::$ZhiMaProxyUrl['password'];
                                    $proxy['from'] = 'zhima';

                                    $realIp = $proxy['originIp'];
                                    //获取 IP 所属地区
                                    $location = self::getIpLocation($realIp);
                                    if(!$location){
                                        $location_address[0] = '未知';
                                    }
                                    $location_address = explode(' ',$location);
                                    $response_arr = [
                                        'IP'=>$proxy['ip'],
                                        'RealIP'=>$realIp,
                                        'Port'=>intval($proxy['port']),
                                        'Address'=>'',
                                        'User'=>$proxy['User'],
                                        'Password'=>$proxy['Password'],
                                        'Location'=>$location_address[0],
                                        'Isp'=>$location_address[1] ?? '未知',
                                        'From'=>$proxy['from'],
                                    ];
                                    return $response_arr;
                                }
                            }
                        }
                    }elseif ($param['from'] == 'tianqi'){
                        //10秒钟不能超过50次-------redis--队列
                        $zhima_len = $redis->llen('tianqi_timestamp');
                        if($zhima_len >= 0 && $zhima_len < 50){
                            $redis->rpush('tianqi_timestamp',time());
                        }elseif($zhima_len >= 50){
                            $key_49 = $redis->lindex('tianqi_timestamp',$zhima_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('tianqi_timestamp',time());
                        }
                        $res = file_get_contents(self::$TianQiProxyUrl['url'],0,$ctx);
                        $this->mysql_insert($res,'tianqi',self::$TianQiProxyUrl['username']);
                        if($res){
                            $res_arr = json_decode($res,true);
                            if(!is_array($res_arr) || $res_arr['code'] != 1000){
                                Log::info('--tianqi代理ip--获取失败01-----');
                                Log::info($res);
                                return null;
                            }

                            $proxy['ip'] = $res_arr['data'][0]['ip'];
                            $proxy['originIp'] = $res_arr['data'][0]['ip'];
                            $proxy['port'] = $res_arr['data'][0]['port'];
                            $proxy['User'] = self::$TianQiProxyUrl['username'];
                            $proxy['Password'] = self::$TianQiProxyUrl['password'];
                            $proxy['from'] = 'tianqi';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }else{
                            Log::info('--tianqi代理ip--获取失败02-----');
                            Log::info($res);
                        }
                    }elseif($param['from'] == 'shenlong'){
                        //10秒钟不能超过50次-------redis--队列
                        $zhima_len = $redis->llen('shenlong_timestamp');
                        if($zhima_len >= 0 && $zhima_len < 50){
                            $redis->rpush('shenlong_timestamp',time());
                        }elseif($zhima_len >= 50){
                            $key_49 = $redis->lindex('shenlong_timestamp',$zhima_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('shenlong_timestamp',time());
                        }
                        $res = file_get_contents(self::$ShenLongProxyUrl['url'],0,$ctx);
                        $this->mysql_insert($res,'shenlong',self::$ShenLongProxyUrl['username']);
                        if($res){
                            $res_arr = json_decode($res,true);
                            if(!is_array($res_arr) || $res_arr['code'] != 200){
                                Log::info('--shenlong代理ip--获取失败01-----');
                                Log::info($res);
                                return null;
                            }

                            $proxy['ip'] = $res_arr['data'][0]['ip'];
                            $proxy['originIp'] = $res_arr['data'][0]['ip'];
                            $proxy['port'] = $res_arr['data'][0]['port'];
                            $proxy['User'] = self::$ShenLongProxyUrl['username'];
                            $proxy['Password'] = self::$ShenLongProxyUrl['password'];
                            $proxy['from'] = 'shenlong';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }else{
                            Log::info('--shenlong代理ip--获取失败02-----');
                            Log::info($res);
                        }
                    }
                }else{
                    return false;
                    //暂时停掉
                    //10秒钟不能超过200次，五分钟不能超过650
                    /*$dailiun_2_len = $redis->llen('dailiun_2_timestamp');
                    if($dailiun_2_len >= 0 && $dailiun_2_len < 50){
                        $redis->rpush('dailiun_2_timestamp',time());
                    }elseif($dailiun_2_len >= 50){
                        $key_49 = $redis->lindex('dailiun_2_timestamp',$dailiun_2_len-49);
                        if(time() - $key_49 <= 10){
                            return false;
                        }
                        $redis->rpush('dailiun_2_timestamp',time());
                    }

                    $proxy_url_1 = static::$proxy_url;
                    $res = file_get_contents($proxy_url_1[1]['url'],0,$ctx);
                    $this->mysql_insert($res,'dailiyun',$proxy_url_1[1]['username']);
                    $arr = explode(':',$res);
                    if(count($arr) == 2){
                        $proxy=[
                            'ip'=>$arr[0],
                            'port' => $arr[1],
                            'User' => $proxy_url_1[1]['username'],
                            'Password' => $proxy_url_1[1]['password'],
                            'from' => 'dailiyun'
                        ];
                        $realIp = $proxy['ip'];
                        //获取 IP 所属地区
                        $location = self::getIpLocation($realIp);
                        if(!$location){
                            $location_address[0] = '未知';
                        }
                        $location_address = explode(' ',$location);
                        $response_arr = [
                            'IP'=>$proxy['ip'],
                            'RealIP'=>$realIp,
                            'Port'=>intval($proxy['port']),
                            'Address'=>'',
                            'User'=>$proxy['User'],
                            'Password'=>$proxy['Password'],
                            'Location'=>$location_address[0],
                            'Isp'=>$location_address[1] ?? '未知',
                            'From'=>$proxy['from'],
                        ];
                        return $response_arr;
                    }*/
                    //暂时停掉代理云 1
                }

            }elseif($param['type'] == 'dongfang'){
                $rand = rand(1,100);
                if($rand >= 50){
                    //10秒钟不能超过50次-------redis--队列
                    $zhima_len = $redis->llen('zhima_timestamp');
                    if($zhima_len >= 0 && $zhima_len < 50){
                        $redis->rpush('zhima_timestamp',time());
                    }elseif($zhima_len >= 50){
                        $key_49 = $redis->lindex('zhima_timestamp',$zhima_len-49);
                        if(time() - $key_49 <= 10){
                            return false;
                        }
                        $redis->rpush('zhima_timestamp',time());
                    }
                    $res = file_get_contents(self::$ShanDongZhiMaProxyUrl['url'],0,$ctx);
                    $this->mysql_insert($res,'zhima',self::$ShanDongZhiMaProxyUrl['username']);
                    if($res){
//                        dump(1);
//                        dump($res);die;
                        $shandong_arr = explode(':',$res);
                        if(count($shandong_arr) == 2){
                            $proxy['ip'] = $shandong_arr[0];
                            $proxy['originIp'] = $shandong_arr[0];
                            $proxy['port'] = $shandong_arr[1];
                            $proxy['User'] = self::$ShanDongZhiMaProxyUrl['username'];
                            $proxy['Password'] = self::$ShanDongZhiMaProxyUrl['password'];
                            $proxy['from'] = 'zhima';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }else{
                            Log::info('山东--芝麻代理ip--获取失败01-----');
                            Log::info($res);
                        }
                    }else{
//                        dump(2);
//                        dump($res);die;
                        Log::info('山东--芝麻代理ip--获取失败02-----');
                        Log::info($res);
                    }
                }else{
                    header('Location:/api/ip/getporxyip?type=job');
                }
            }elseif ($param['type'] == 'baoguang'){
                if(isset($param['from']) && !empty($param['from'])){
                    if($param['from'] == 'dailiyun'){
                        //10秒钟不能超过200次，五分钟不能超过650
                        $dailiun_2_len = $redis->llen('dailiun_2_timestamp');
                        if($dailiun_2_len >= 0 && $dailiun_2_len < 50){
                            $redis->rpush('dailiun_2_timestamp',time());
                        }elseif($dailiun_2_len >= 50){
                            $key_49 = $redis->lindex('dailiun_2_timestamp',$dailiun_2_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('dailiun_2_timestamp',time());
                        }

                        $proxy_url_1 = static::$proxy_url;
                        $res = file_get_contents($proxy_url_1[1]['url'],0,$ctx);
                        $this->mysql_insert($res,'dailiyun',$proxy_url_1[1]['username']);
                        $arr = explode(':',$res);
                        if(count($arr) == 2){
                            $proxy=[
                                'ip'=>$arr[0],
                                'port' => $arr[1],
                                'User' => $proxy_url_1[1]['username'],
                                'Password' => $proxy_url_1[1]['password'],
                                'from' => 'dailiyun'
                            ];
                            $realIp = $proxy['ip'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }
                        //暂时停掉代理云 1
                    }elseif ($param['from'] == 'zhima'){
                        //10秒钟不能超过50次-------redis--队列
                        $zhima_len = $redis->llen('zhima_timestamp');
                        if($zhima_len >= 0 && $zhima_len < 50){
                            $redis->rpush('zhima_timestamp',time());
                        }elseif($zhima_len >= 50){
                            $key_49 = $redis->lindex('zhima_timestamp',$zhima_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('zhima_timestamp',time());
                        }
                        $res = file_get_contents(self::$ZhiMaProxyUrl['url'],0,$ctx);
                        $this->mysql_insert($res,'zhima',self::$ZhiMaProxyUrl['username']);
                        if($res){
                            $arr = json_decode($res,true);
                            if(isset($arr['success'])){
                                if(isset($arr['data']) && !empty($arr['data'])){
                                    $proxy['ip'] = $arr['data'][0]['ip'];
                                    $proxy['originIp'] = $arr['data'][0]['outip'];
                                    $proxy['port'] = $arr['data'][0]['port'];
                                    $proxy['User'] = self::$ZhiMaProxyUrl['username'];
                                    $proxy['Password'] = self::$ZhiMaProxyUrl['password'];
                                    $proxy['from'] = 'zhima';

                                    $realIp = $proxy['originIp'];
                                    //获取 IP 所属地区
                                    $location = self::getIpLocation($realIp);
                                    if(!$location){
                                        $location_address[0] = '未知';
                                    }
                                    $location_address = explode(' ',$location);
                                    $response_arr = [
                                        'IP'=>$proxy['ip'],
                                        'RealIP'=>$realIp,
                                        'Port'=>intval($proxy['port']),
                                        'Address'=>'',
                                        'User'=>$proxy['User'],
                                        'Password'=>$proxy['Password'],
                                        'Location'=>$location_address[0],
                                        'Isp'=>$location_address[1] ?? '未知',
                                        'From'=>$proxy['from'],
                                    ];
                                    return $response_arr;
                                }
                            }
                        }
                    }elseif ($param['from'] == 'tianqi'){
                        //10秒钟不能超过50次-------redis--队列
                        $zhima_len = $redis->llen('tianqi_timestamp');
                        if($zhima_len >= 0 && $zhima_len < 50){
                            $redis->rpush('tianqi_timestamp',time());
                        }elseif($zhima_len >= 50){
                            $key_49 = $redis->lindex('tianqi_timestamp',$zhima_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('tianqi_timestamp',time());
                        }
                        $res = file_get_contents(self::$TianQiProxyUrl['url'],0,$ctx);
                        $this->mysql_insert($res,'tianqi',self::$TianQiProxyUrl['username']);
                        if($res){
                            $res_arr = json_decode($res,true);
                            if(!is_array($res_arr) || $res_arr['code'] != 1000){
                                Log::info('--tianqi代理ip--获取失败01-----');
                                Log::info($res);
                                return null;
                            }

                            $proxy['ip'] = $res_arr['data'][0]['ip'];
                            $proxy['originIp'] = $res_arr['data'][0]['ip'];
                            $proxy['port'] = $res_arr['data'][0]['port'];
                            $proxy['User'] = self::$TianQiProxyUrl['username'];
                            $proxy['Password'] = self::$TianQiProxyUrl['password'];
                            $proxy['from'] = 'tianqi';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }else{
                            Log::info('--tianqi代理ip--获取失败02-----');
                            Log::info($res);
                        }
                    }elseif($param['from'] == 'shenlong'){
                        //10秒钟不能超过50次-------redis--队列
                        $zhima_len = $redis->llen('shenlong_timestamp');
                        if($zhima_len >= 0 && $zhima_len < 50){
                            $redis->rpush('shenlong_timestamp',time());
                        }elseif($zhima_len >= 50){
                            $key_49 = $redis->lindex('shenlong_timestamp',$zhima_len-49);
                            if(time() - $key_49 <= 10){
                                return false;
                            }
                            $redis->rpush('shenlong_timestamp',time());
                        }
                        $res = file_get_contents(self::$ShenLongProxyUrl['url'],0,$ctx);
                        $this->mysql_insert($res,'shenlong',self::$ShenLongProxyUrl['username']);
                        if($res){
                            $res_arr = json_decode($res,true);
                            if(!is_array($res_arr) || $res_arr['code'] != 200){
                                Log::info('--shenlong代理ip--获取失败01-----');
                                Log::info($res);
                                return null;
                            }

                            $proxy['ip'] = $res_arr['data'][0]['ip'];
                            $proxy['originIp'] = $res_arr['data'][0]['ip'];
                            $proxy['port'] = $res_arr['data'][0]['port'];
                            $proxy['User'] = self::$ShenLongProxyUrl['username'];
                            $proxy['Password'] = self::$ShenLongProxyUrl['password'];
                            $proxy['from'] = 'shenlong';

                            $realIp = $proxy['originIp'];
                            //获取 IP 所属地区
                            $location = self::getIpLocation($realIp);
                            if(!$location){
                                $location_address[0] = '未知';
                            }
                            $location_address = explode(' ',$location);
                            $response_arr = [
                                'IP'=>$proxy['ip'],
                                'RealIP'=>$realIp,
                                'Port'=>intval($proxy['port']),
                                'Address'=>'',
                                'User'=>$proxy['User'],
                                'Password'=>$proxy['Password'],
                                'Location'=>$location_address[0],
                                'Isp'=>$location_address[1] ?? '未知',
                                'From'=>$proxy['from'],
                            ];
                            return $response_arr;
                        }else{
                            Log::info('--shenlong代理ip--获取失败02-----');
                            Log::info($res);
                        }

                    }
                }else{
                    //10秒钟不能超过50次-------redis--队列
                    /*$zdaye_len = $redis->llen('ip_pond_timestamp');
                    if($zdaye_len >= 0 && $zdaye_len < 50){
                        $redis->rpush('ip_pond_timestamp',time());
                    }elseif($zdaye_len >= 50){
                        $key_49 = $redis->lindex('ip_pond_timestamp',$zdaye_len-49);
                        if(time() - $key_49 <= 10){
                            return false;
                        }
                        $redis->rpush('ip_pond_timestamp',time());
                    }*/

                    $pond = $this->getIpFromProxyIpList();
                    if(is_array($pond)){
                        $from = $pond['from'];
                        $this->mysql_insert(json_encode($pond),$from,$pond['user']);
                        $proxy['ip'] = $pond['ip'];
                        $proxy['originIp'] = $pond['ip'];
                        $proxy['port'] = $pond['port'];
                        $proxy['User'] = $pond['user'];
                        $proxy['Password'] = $pond['password'];
                        $proxy['from'] = $pond['from'];
                        //获取 IP 所属地区
                        $location = self::getIpLocation($pond['ip']);
                        if(!$location){
                            $location_address[0] = '未知';
                        }
                        $location_address = explode(' ',$location);
                        $response_arr = [
                            'IP'=>$pond['ip'],
                            'RealIP'=>$pond['ip'],
                            'Port'=>intval($pond['port']),
                            'Address'=>'',
                            'User'=>$pond['user'],
                            'Password'=>$pond['password'],
                            'Location'=>$location_address[0],
                            'Isp'=>$pond['isp'],
                            'From'=>$pond['from'],
                        ];
                        return $response_arr;
                    }else{
                        Log::info('---ip_pond-----代理ip--获取失败01-----');
                        Log::info(json($pond));
                    }
                }

            }
        }catch (\Exception $e){
            return null;
        }
        return null;
    }


    /**
     * 获取普通代理IP
     * @return string[]
     */
    public function getProxyIp()
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);

        $rand = rand(0,1000);
        if($rand < 400){
            //10秒钟不能超过200次，五分钟不能超过700-------redis--队列
            $dailiun_1_len = $redis->lLen('dailiun_1_timestamp');
            if($dailiun_1_len >= 0 && $dailiun_1_len < 20){
                $redis->rpush('dailiun_1_timestamp',time());
            }elseif($dailiun_1_len >= 20 && $dailiun_1_len < 700){
                $key_20 = $redis->lindex('dailiun_1_timestamp',19);
                if(time() - $key_20 <= 10){
//                    return 'dailiun_1 10秒超过20次';
                    return false;
                }
                $redis->rpush('dailiun_1_timestamp',time());
            }elseif($dailiun_1_len >= 700){
                $key_699 = $redis->lindex('dailiun_1_timestamp',699);
                if(time() - $key_699 <= 300){
//                    return 'dailiun_1 5分钟超过300次';
                    return false;
                }
                $redis->rpush('dailiun_1_timestamp',time());
            }
            $proxy = self::$proxy_url[0];
        }elseif ($rand >= 400 && $rand < 700){
            //10秒钟不能超过200次，五分钟不能超过650
            $dailiun_2_len = $redis->llen('dailiun_2_timestamp');
            if($dailiun_2_len >= 0 && $dailiun_2_len < 20){
                $redis->rpush('dailiun_2_timestamp',time());
            }elseif($dailiun_2_len >= 20 && $dailiun_2_len < 650){
                $key_20 = $redis->lindex('dailiun_2_timestamp',19);
                if(time() - $key_20 <= 10){
//                    return 'dailiun_2 10秒超过20次';
                    return false;
                }
                $redis->rpush('dailiun_2_timestamp',time());
            }elseif($dailiun_2_len >= 650){
                $key_649 = $redis->lindex('dailiun_2_timestamp',649);
                if(time() - $key_649 <= 300){
//                    return 'dailiun_2 5分钟超过300次';
                    return false;
                }
                $redis->rpush('dailiun_2_timestamp',time());
            }
            $proxy = self::$proxy_url[1];
        }elseif ($rand >= 700){
            //10秒钟不能超过200次，五分钟不能超过500
            $dailiun_3_len = $redis->llen('dailiun_3_timestamp');
            if($dailiun_3_len >= 0 && $dailiun_3_len < 20){
                $redis->rpush('dailiun_3_timestamp',time());
            }elseif($dailiun_3_len >= 20 && $dailiun_3_len < 500){
                $key_20 = $redis->lindex('dailiun_3_timestamp',19);
                if(time() - $key_20 <= 10){
//                    return 'dailiun_3 10秒超过20次';
                    return false;
                }
                $redis->rpush('dailiun_3_timestamp',time());
            }elseif($dailiun_3_len >= 500){
                $key_499 = $redis->lindex('dailiun_3_timestamp',499);
                if(time() - $key_499 <= 300){
//                    return 'dailiun_3 5分钟超过300次';
                    return false;
                }
                $redis->rpush('dailiun_3_timestamp',time());
            }
            $proxy = self::$proxy_url[2];
        }
//        return 1;
        $res = file_get_contents($proxy['url']);
        if(!$res){
            return false;
        }
        $arr = explode(':',$res);
        if(count($arr) <= 1){ //没有端口号返回 null
            return false;
        }
        $proxy=[
            'ip'=>$arr[0],
            'port' => $arr[1],
            'User' => $proxy['username'],
            'Password' => $proxy['password'],
            'from' => 'dailiyun'
        ];
//        var_dump($proxy);die;
        return $proxy;

    }

    /**
     * 获取xiaoxiong代理IP
     * @return string
     */
    public function getXiaoXionProxyIp()
    {
        $proxy = [];
        $res = file_get_contents(self::$XiaoXiongProxyUrl);
//        dump($res);die;
        if(!$res){
            return false;
        }

        $arr = json_decode($res,true);
        if($arr['status'] !=0){
            return false;
        }
        if(isset($arr['list']) && !empty($arr['list'])){
            $proxy['ip'] = $arr['list'][0]['sever'];
            $proxy['originIp'] = $arr['list'][0]['ip'];
            $proxy['port'] = $arr['list'][0]['port'];
            $proxy['User'] = '';
            $proxy['Password'] = '';
            $proxy['from'] = 'xiaoxiong';
            return $proxy;
        }
        return false;

    }

    /**
     * 获取xiaoxiong代理IP
     * @return string
     */
    public function getZhiMaProxyIp()
    {
        $proxy = [];
        $res = file_get_contents(self::$ZhiMaProxyUrl['url']);
        if(!$res){
            return false;
        }
        $arr = json_decode($res,true);
        if(!$arr['success']){
            return false;
        }
        if(isset($arr['data']) && !empty($arr['data'])){
            $proxy['ip'] = $arr['data'][0]['ip'];
            $proxy['originIp'] = $arr['data'][0]['outip'];
            $proxy['port'] = $arr['data'][0]['port'];
            $proxy['User'] = self::$ZhiMaProxyUrl['username'];
            $proxy['Password'] = self::$ZhiMaProxyUrl['password'];
            $proxy['from'] = 'zhima';
            return $proxy;
        }
        return false;
    }


    /**
     * 检测 IP地址 60s 内有没有用过
     * @param $ip
     * @return bool
     */
    public function check60sOfIp($ip)
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        if ($redis->exists($ip)){
            return true;
        }
        return false;
    }

    /**
     * 检测 IP 24小时 有没有用过
     * @param $ip
     * @return false
     */
    public function check24hOfIp($ip)
    {
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        if ($redis->exists('dayIp:'.$ip)){
            return $redis->get('dayIp:'.$ip);
        }else{
            $redis->setex('dayIp:'.$ip,86400,0);
            return false;
        }
    }

    /**
     * 获取 IP 地址所属地区以及运营商信息
     * @param $ip
     * @return false|mixed
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function getIpLocation($ip)
    {
        $url = self::$getLocationUrl.$ip;

        $client = new Client();
        $response = $client->get($url);
        $res = $response->getBody()->getContents();
        $data = json_decode($res,true);
        if($data['status'] == 0){
            $res = $data['data'][0];
            if(isset($res['location']) && $res['location']){
                return $res['location'];
            }
        }
        return false;
    }

    public function mysql_insert($res,$from,$from_account){
        $data['detail']      = $res;
        $data['from'] = $from;
        $data['from_account'] = $from_account;
        $data['create_time'] = date('Y-m-d H:i:s');
        Db::name('getip_error_log')->insert($data);
    }

    public function get_zdaye_redis(){
        $zdaye_res = curl_get(self::$ZDaYeProxyUrl['url']);
        return $zdaye_res;
    }
    public function get_shenlong_redis(){
        $shenlong_res = curl_get(self::$ShenLongProxyUrl['url']);
        return $shenlong_res;
    }

    /**
     * 检测IP过期时间
     * 如果已经过期则继续取值，一直到没有获有效地值
     * @return false|mixed
     */
    private static function getIpFromProxyIpList(){
        $redis = new \Redis();
        $redis->connect('127.0.0.1', 6379);
        $redis->select(2);

        if($redis->lLen('ProxyIpList') > 0){
            $ipStr = $redis->lpop('ProxyIpList');
            $ip = json_decode($ipStr,true);
            $data['ip'] = $ip['ip'];
            $data['expire_time'] = $ip['time'];
            $data['from'] = $ip['from'];
            $data['ip_str'] = $ipStr;
            $data['collect_time'] = time();
            $data['create_time'] = date('Y-m-d H:i:s');
            if(time() >= $ip['time']){
                $data['status'] = 0;
                Db::name('ip_logs')->insert($data);
                self::getIpFromProxyIpList();
            }else{
                $data['status'] = 1;
                Db::name('ip_logs')->insert($data);
                return $ip;
            }
        }else{
            return false;
        }

    }



}
